//
//  YouLovedTableViewCell.m
//  Youhuiju
//
//  Created by yutenys on 16/7/27.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "YouLovedTableViewCell.h"
@interface YouLovedTableViewCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIButton *moreBtn;
@property (weak, nonatomic) IBOutlet UIImageView *sectionImg;

//适配
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleImgHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnTrailing;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnHig;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *moreBtnWid;
@end

@implementation YouLovedTableViewCell

static NSString *YouLovedCollectionViewCellIden  = @"YouLovedCollectionViewCellIden";

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.titleImgHig.constant = 50 * FitH;
    self.moreBtnTrailing.constant = 20 * FitW;
    self.moreBtnHig.constant = 30 * FitH;
    self.moreBtnWid.constant = 50 * FitW;
    self.moreBtn.titleLabel.font = [UIFont systemFontOfSize:11 * FitH];
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"YouLovedCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:YouLovedCollectionViewCellIden];
    
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 6;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(124 * FitW, 190 * FitH);
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    YouLovedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:YouLovedCollectionViewCellIden forIndexPath:indexPath];
    cell.buttonDelegate = self;
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.cellDelegate cellClickedJump];
}


- (IBAction)moreButtonCkickedAction:(UIButton *)sender {
    
    if (self.moreButtonClickedHandler)
    {
        self.moreButtonClickedHandler();
    }
}




#pragma mark ------ private delegate

-(void)buttonClickedJump:(NSInteger)buttonTag :(NSString *)categoryString
{
    [self.cellButtonDelegate cellButtonClickedJump:buttonTag :categoryString];
}



#pragma amrk --- setter
-(void)setImgUrl:(NSString *)imgUrl
{
    if (_imgUrl != imgUrl)
    {
        _imgUrl = imgUrl;
        
        self.sectionImg.image = LoadImage(imgUrl);
    }
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
